package operation;

import book.Booklist;
import book.*;

import java.util.Scanner;

public class Borrow implements IOperation {

    @Override
    public void work(Booklist booklist) {
        System.out.print("请输入要借阅的图书名：");
        Scanner scan = new Scanner(System.in);
        String name = scan.nextLine();
        for(int i = 0; i < booklist.getNum(); i++) {
            Book book = booklist.getBook(i);
            if (book.getName().equals(name)) {
                if (book.isCondition()) {
                    System.out.println("该图书已被借出！");
                } else {
                    System.out.println("您确定要借阅此书吗？");
                    System.out.println("1->确定    0.取消");
                    int c = scan.nextInt();
                    if (c == 1) {
                        System.out.println("您已成功借出！");
                        book.setCondition(true);
                    } else {
                        System.out.println("请重新操作。");
                    }
                }
                 break;
            }
            if (i == booklist.getNum() - 1) {
                System.out.println("没找到相关书籍！");
                break;
            }
        }
    }
}
